package com.ysg.widget.flow;

import android.view.View;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public abstract class TagAdapter {
    interface OnDataChangedListener {
        void onChanged();
    }
    private OnDataChangedListener mOnDataChangedListener;
    void setOnDataChangedListener(OnDataChangedListener listener) {
        mOnDataChangedListener = listener;
    }
    //=======================================================================

    private List<String> list;
    private HashSet<Integer> mCheckedPosList = new HashSet<>();

    public TagAdapter(List<String> list) {
        this.list = list;
    }

    //初始化时：默认选中的item
    public void setCheckedList(Set<Integer> set) {
        mCheckedPosList.clear();
        if (set != null) {
            mCheckedPosList.addAll(set);
        }
        notifyDataChanged();
    }

    HashSet<Integer> getCheckedList() {
        return mCheckedPosList;
    }

    public int getCount() {
        return list == null ? 0 : list.size();
    }

    public void notifyDataChanged() {
        if (mOnDataChangedListener != null)
            mOnDataChangedListener.onChanged();
    }

    public String getItem(int position) {
        return list.get(position);
    }

    public abstract View getView(int position, String t);

    public void onSelected(int position, View view){
    }

    public void unSelected(int position, View view){
    }

    public boolean setSelected(int position, String t) {
        return false;
    }


}
